Passed
Pull Request — master (#159)
by Mathieu
01:35
created

GetCooperativeQueryHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 8 2
1
import { QueryHandler } from '@nestjs/cqrs';
2
import { Inject } from '@nestjs/common';
3
import { GetCooperativeQuery } from './GetCooperativeQuery';
4
import { ICooperativeRepository } from 'src/Domain/Settings/Repository/ICooperativeRepository';
5
import { CooperativeNotFoundException } from 'src/Domain/Settings/Repository/CooperativeNotFoundException';
6
import { CooperativeView } from '../View/CooperativeView';
7
8
@QueryHandler(GetCooperativeQuery)
9
export class GetCooperativeQueryHandler {
10
  constructor(
11
    @Inject('ICooperativeRepository')
12
    private readonly cooperativeRepository: ICooperativeRepository
13
  ) {}
14
15
  public async execute(query: GetCooperativeQuery): Promise<CooperativeView> {
16
    const cooperative = await this.cooperativeRepository.find();
17
    if (!cooperative) {
18
      throw new CooperativeNotFoundException();
19
    }
20
21
    return new CooperativeView(cooperative.getDayDuration());
22
  }
23
}
24